/**
 * Created by Administrator on 2017/10/24 0024.
 */
layui.use(['element','form'], function() {
    var form = layui.form;
    var element = layui.element;


    var setting = {
        check: {
            enable: true
        },
        data: {
            simpleData: {
                enable: true
            }
        }
    };

    $.ajax({
        url:"/role/tree",
        type:"get",
        dataType:"json",
        success:function (msg) {
            var zNodes =msg.data;//获取数据
            $.fn.zTree.init($("#treeRole"), setting, zNodes); //初始化节点树
            console.log("节点数加载成功！")
        },
        error:function () {
            console.log("节点数加载失败！")
        }
    })

    //监听提交
    form.on('submit(formSubmit)', function(data){
        var treeObj = $.fn.zTree.getZTreeObj("treeRole");  //获取树对象
        var nodes = treeObj.getCheckedNodes(true);  //获取树的选中节点
        var ids=[];
        $.each(nodes,function (i,item) {
            ids.push(item.id);
        })
        $("#premssionIds").val(ids.join(","));//将选中节点的id拼接为字符串，放入到form中的隐藏域中
        return true;
    })

})